package com.usian.behavior.rabbit;

import com.alibaba.fastjson.JSON;
import com.usian.behavior.service.ApFollowBehaviorService;
import com.usian.common.constants.BehaviorConstant;
import com.usian.model.behavior.dtos.FollowBehaviorDto;
import org.apache.commons.lang3.StringUtils;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@RabbitListener(queuesToDeclare = @Queue(value = BehaviorConstant.FOLLOW_BEHAVIOR_ROUTING_KEY, durable = "true", autoDelete = "true"))
public class FollowBehaviorMessage {
    @Autowired
    private ApFollowBehaviorService service;

    @RabbitHandler
    public void getMessage(String message) {
        if (StringUtils.isNotBlank(message)) {
            FollowBehaviorDto behaviorDto = JSON.parseObject(message, FollowBehaviorDto.class);
            service.saveFollowBehavior(behaviorDto);
        } else System.out.println("没有收到关注行为的消息");
    }
}
